#include <stdio.h>
#include <string.h>

#include "calc.h"

char inbuf[1024];
char *ic;

int main ()
{
    calc_t result;
    Tree ast = NULL;

    printf("\n;; please input an arithmetic expression:\n");
    printf(";; press Ctrl-D to quit.\n\n");
    for ( ; ; ) {
        if (fgets(inbuf, 1024, stdin) == NULL)
            break;
        ast = parse_expr();
        if (ast != NULL && gtoken.type == T_EOF) {
            result = eval_ast(ast);
            printf("\t= %lf\n\n", result);
        } else
            fprintf(stderr, "unexpected end of expression.\n");
        free_ast(ast);
        memset(inbuf, 0, sizeof(inbuf));
        ic = inbuf;
    }
    return 0;
}
